package cn.chenshi.excel.config;

import cn.chenshi.excel.ExcelService;
import cn.chenshi.excel.model.ExcelLocalBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(ExcelProperties.class)
@ConditionalOnClass(ExcelLocalBean.class)
@ConditionalOnWebApplication
public class ExcelStarterAutoConfiguration {


    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnProperty(prefix = "oss.config", name = "enable", havingValue = "true")
    public ExcelLocalBean defaultExcelLocalBean(ExcelProperties ossProperties) {
        String a = ossProperties.getA();
        ExcelLocalBean excelLocalBean = new ExcelLocalBean();
        excelLocalBean.setA(a);

        return excelLocalBean;
    }

    @Bean
    @ConditionalOnMissingBean
    public ExcelService ossService () {
        return new ExcelService();
    }
}

